package cn.wolfcode.luowowo2.mgrsite.web.controller;

import cn.wolfcode.luowowo2.article.domain.Destination;
import cn.wolfcode.luowowo2.article.service.IDestinationService;
import cn.wolfcode.luowowo2.common.query.DestinationQueryObject;
import cn.wolfcode.luowowo2.common.query.QueryObject;
import cn.wolfcode.luowowo2.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Albert on 2019/7/8.
 */
@Controller
@RequestMapping("destination")
public class DestinationController {
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") DestinationQueryObject qo){
        PageInfo<Destination> pageInfo = destinationService.query(qo);
        model.addAttribute("pageInfo",pageInfo);

        List<Destination> toasts = destinationService.getToastList(qo.getParentId());
        model.addAttribute("toasts",toasts);

        return "destination/list";
    }
    @RequestMapping("changeHotValue")
    @ResponseBody
    public AjaxResult changeHotValue(Boolean hot, Long id){
        AjaxResult ajaxResult = new AjaxResult();
        destinationService.changeHotValue(hot,id);
        return ajaxResult;
    }

    @RequestMapping("setInfo")
    @ResponseBody
    public AjaxResult setInfo(String info, Long id){
        AjaxResult ajaxResult = new AjaxResult();
        destinationService.setInfo(info,id);
        return ajaxResult;
    }

    @RequestMapping("delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        AjaxResult ajaxResult = new AjaxResult();
        //destinationService.delete(id);
        return ajaxResult;
    }
}
